﻿using System;
using MoroMoro.Samples.ToDoList.Base.Application;
using MoroMoro.Samples.ToDoList.Base.Persistence;
using MoroMoro.Samples.ToDoList.Domain.Categories;

namespace MoroMoro.Samples.ToDoList.Application.Categories
{
    /// <summary>
    /// <see cref="Category">カテゴリ</see>の一覧を読み込むスクリプトです。
    /// </summary>
    [Serializable]
    internal sealed class CategoryListLoadScript : WorkScript<CategoryListLoadOutputs, CategoryListLoadErrors>
    {
        /// <summary>
        /// <see cref="CategoryListLoadScript"/> クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="workspace">作業スペース。</param>
        /// <exception cref="System.ArgumentNullException">workspace が null です。</exception>
        public CategoryListLoadScript(IWorkspace workspace)
            : base(workspace)
        {
        }

        
        /// <inheritdoc/>
        protected override ExecutionResult ExecuteCore()
        {
            var order = new CategoryNameViewpoint().Asc();
            var list = Workspace.GetRepository<Category>().FindAll(order);

            return new CategoryListLoadOutputs
            {
                List = list
            };
        }
    }
}
